package game.module.hall.processor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import game.HallServer;
import game.common.PlayingRoleMsgProcessor;
import game.entity.PlayingRole;
import game.module.hall.logic.QipaiConstants;
import game.module.hall.logic.QipaiDataManager;
import lion.common.MsgCodeAnn;
import lion.netty4.message.MyRequestMessage;
import lion.netty4.message.RequestMessageRaw;
import lion.netty4.message.RequestProtoMessage;
import lua.LuaMessageDdz.C2SJoinRoom;
import lua.LuaMessageHall.C2SFastJoinRoom;
import lua.LuaMessageHall.S2CFastJoinRoom;
import lua.LuaMessageLogin.S2ErrorCode;
import lua.LuaMessageMj.C2SMJJoinRoom;
import lua.LuaMessageNn.C2SNNJoinRoom;
import lua.LuaMessageQzmj.C2SQzmjJoinRoom;
import lua.LuaMessageSss.C2SSSSJoinRoom;

@MsgCodeAnn(msgcode = C2SFastJoinRoom.id, accessLimit = 500)
public class FastJoinRoomProcessor extends PlayingRoleMsgProcessor {

	private static Logger logger = LoggerFactory.getLogger(FastJoinRoomProcessor.class);

	@Override
	public void process(PlayingRole hero, RequestMessageRaw request) throws Exception {
		C2SFastJoinRoom reqMsg = C2SFastJoinRoom.parse(request);
		String room_id = reqMsg.room_id;
		int playerId = hero.getId();
		logger.info("fast join room,playeyId={},room_id={}", playerId, room_id);
		Byte roomType = QipaiDataManager.getInstance().getRoomType(room_id);
		if (roomType == null) {
			S2ErrorCode respMsg = new S2ErrorCode(104);
			hero.writeAndFlush(respMsg.build(hero.alloc()));
			return;
		}
		switch (roomType) {
		case QipaiConstants.ROOM_TYPE_DDZ:
			((PlayingRoleMsgProcessor) HallServer.getInstance().getMsgProcessor(C2SJoinRoom.id)).process(hero, request);
			break;
		case QipaiConstants.ROOM_TYPE_NN:
			((PlayingRoleMsgProcessor) HallServer.getInstance().getMsgProcessor(C2SNNJoinRoom.id)).process(hero,
					request);
			break;
		case QipaiConstants.ROOM_TYPE_SSS:
			((PlayingRoleMsgProcessor) HallServer.getInstance().getMsgProcessor(C2SSSSJoinRoom.id)).process(hero,
					request);
			break;
		case QipaiConstants.ROOM_TYPE_MJ:
			((PlayingRoleMsgProcessor) HallServer.getInstance().getMsgProcessor(C2SMJJoinRoom.id)).process(hero,
					request);
			break;
		case QipaiConstants.ROOM_TYPE_MJ_QZ:
			((PlayingRoleMsgProcessor) HallServer.getInstance().getMsgProcessor(C2SQzmjJoinRoom.id)).process(hero,
					request);
			break;
		default:
			break;
		}
		// ret
		S2CFastJoinRoom respMsg = new S2CFastJoinRoom(room_id, roomType);
		hero.writeAndFlush(respMsg.build(hero.alloc()));
	}

	@Override
	public void processProto(PlayingRole playingRole, RequestProtoMessage request) throws Exception {
		// null
	}

	@Override
	public void processWebsocket(PlayingRole playingRole, MyRequestMessage request) throws Exception {
		// null
	}

}
